package cc.mrbird.febs.common.utils;

import io.swagger.annotations.ApiModelProperty;

/**
 * @author: louyz
 * @date: 2019-10-23 15:45
 * @description: 通用响应类
 */
public class Result<T> {

    public static final int SUCCESS = 1;
    public static final int FAIL = 0;

    @ApiModelProperty(value = "结果码", dataType = "Integer", required = true)
    private int status;

    @ApiModelProperty(value = "结果描述", dataType = "String", required = true)
    private String message;

    @ApiModelProperty(value = "响应数据对象")
    private T data;

    public Result() {
    }

    public Result(int status, String message) {
        this.status = status;
        this.message = message;
        this.data = null;
    }

    public Result(T data) {
        this.status = SUCCESS;
        this.message = "SUCCESS";
        this.data = data;
    }

    public Result(int status, T data, String message) {
        this.status = status;
        this.data = data;
        this.message = message;
    }


    public static <T> Result<T> custom(int status, T t, String message) {
        return new Result<>(status, t, message);
    }

    public static <T> Result<T> custom(int status, String message) {
        return new Result<>(status, message);
    }

    public static <T> Result<T> success(T t, String message) {
        return new Result<>(SUCCESS, t, message);
    }
    public static <T> Result<T> success(T t) {
        return new Result<>(SUCCESS, t, "操作成功");
    }

    public static <T> Result<T> success(String message) {
        return new Result<>(SUCCESS, message);
    }

    public static <T> Result<T> fail(T t, String message) {
        return new Result<>(FAIL, t, message);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(FAIL, message);
    }

    public static Result<String> success() {
        return new Result<>(SUCCESS, "操作成功");
    }

    public static Result<String> fail() {
        return new Result<>(FAIL, "操作失败");
    }

    public int getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }
}
